package org.zfes.snowier.cloud.zbss.pmp.router.service.pm;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.core.util.ZStrUtil;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.auth.shiro.util.SecurityUtil;
import org.zfes.snowier.cloud.zbss.pmp.dto.PmpBugsAssignDto;
import org.zfes.snowier.cloud.zbss.pmp.dto.PmpBugsCreateDto;
import org.zfes.snowier.cloud.zbss.pmp.model.PmpBugs;
import org.zfes.snowier.cloud.zbss.pmp.model.PmpBugsRecord;
import org.zfes.snowier.cloud.zbss.pmp.service.IPmpBugsRecordService;
import org.zfes.snowier.cloud.zbss.pmp.service.IPmpBugsService;
@Controller("org.zfes.snowier.cloud.zbss.pmp.router.service.pm.pmpBugsController") 
@RequestMapping("/pmp/service/pm/pmpBugs")
public class PmpBugsController extends BaseController {

	
	@Autowired
	private IPmpBugsService pmpBugsService;

	@Autowired
	private IPmpBugsRecordService pmpBugsRecordService;
	
	@RequestMapping(value="/loadRecordByBugId", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadRecordByBugId(Long bugId){
		List<PmpBugsRecord> recordList=  pmpBugsRecordService.loadRecordByBugId(bugId);
	    return ajaxQuery("recordList", recordList);
    }
	
	
	@RequestMapping(value="/assignPmpBugs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object assignPmpBugs(PmpBugsAssignDto assignDto){
		pmpBugsService.assignPmpBugs(assignDto);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/loadPmpBugsDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadPmpBugsDataSet(@RequestParam Map<String,Object> params){
	    DataSet dataSet=  pmpBugsService.loadPmpBugsDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
    
	
    @RequestMapping(value="/loadPmpBugs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadPmpBugs(Long id){
		Optional<PmpBugs> ops = pmpBugsService.loadPmpBugsById(id);
		return ajaxQuery("pmpBugs",ops);
    }

    
    @RequestMapping(value="/pmCheckBugs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object  pmCheckBugs(String ids, Byte accept) {
    	pmpBugsService.pmCheckBugs(ZStrUtil.splitLong(ids),accept);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
    

   // bug状态_D#1未指派,2待解决,3进行中,4修改并提交,5测试验收,6测试驳回,7经理驳回,8已完成,9延期处理-1已删除#
    @RequestMapping(value="/setPmpBugsStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object setPmpBugsStatusByPm(Long id, Byte status){
		pmpBugsService.setPmpBugsStatusByPm(id, status);
    	return ajaxDoneSuccess("数据操作成功 ");
    }

}